package com.lanou.wuyou.gift.category;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.wuyou.gift.R;
import com.lanou.wuyou.gift.bean.CategoryProductBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dllo on 17/3/20.
 */

public class CategoryProductRightItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private List<CategoryProductBean.DataBean.CategoriesBean.SubcategoriesBean> bean;
    private Context context;


    public CategoryProductRightItemAdapter(Context context) {
        this.context = context;
    }

    public void setBean(List<CategoryProductBean.DataBean.CategoriesBean.SubcategoriesBean> bean) {
        this.bean = bean;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        View view = LayoutInflater.from(context).inflate(R.layout.item_category_product_right_content,null);
        viewHolder = new CategoryHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        CategoryHolder categoryHolder = (CategoryHolder) holder;
        if (bean != null){
            Picasso.with(context).load(bean.get(position).getIcon_url()).into(categoryHolder.iconIv);
            categoryHolder.nameTv.setText(bean.get(position).getName());
        }
    }

    @Override
    public int getItemCount() {


        return bean != null && bean.size() > 0 ? bean.size() : 0;
    }
    class CategoryHolder extends RecyclerView.ViewHolder{
        TextView nameTv;
        ImageView iconIv;
        public CategoryHolder(View itemView) {
            super(itemView);
            nameTv = (TextView) itemView.findViewById(R.id.content_product_right_tv);
            iconIv = (ImageView) itemView.findViewById(R.id.content_product_right_iv);
        }
    }
}
